// common/components/me ga ga me.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    dic: { // 属性名
      type: Object, // 类型（必填），目前接受的类型包括：String, Number, Boolean, Object, Array, null（表示任意类型）
      value: '', // 属性初始值（可选），如果未指定则会根据类型选择一个
      observer: function(newVal, oldVal) {
        if (newVal.match_status == 21) {
          this.setData({
            megameStatus: '未开始',
            voteBtnW: 100
          })
          if (newVal.user_permission == 0) {
            this.setData({
              hidenBtn: true,
              hidenLockImage: false
            })
          } else if (newVal.user_permission & 1) {
            this.setData({
              hidenBtn: false,
              hidenLockImage: true,
              megameActive: '我投稿',
              voteBtnBackColor: 'rgba(107, 211, 165,1)'
            })
          } else {
            this.setData({
              hidenBtn: true,
              hidenLockImage: false
            })
          }
        } else if (newVal.match_status == 22) {
          this.setData({
            megameStatus: '征稿中',
            voteBtnW: 100
          })
          if (newVal.user_permission == 0) {
            this.setData({
              hidenBtn: true,
              hidenLockImage: false
            })
          } else if (newVal.user_permission & 1) {
            this.setData({
              hidenBtn: false,
              hidenLockImage: true,
              megameActive: '我投稿',
              voteBtnBackColor: 'rgba(107, 211, 165,1)'
            })
          } else {
            this.setData({
              hidenBtn: false,
              hidenLockImage: true,
              megameActive: '查看投稿',
              voteBtnBackColor: '#ff7e00'
            })
          }
        } else if (newVal.match_status == 23) {
          this.setData({
            megameStatus: '评选中',
            voteBtnW: 100
          })
          if (newVal.user_permission == 0) {
            this.setData({
              hidenBtn: true,
              hidenLockImage: false
            })
          } else if (newVal.user_permission & 2) {
            this.setData({
              hidenBtn: false,
              hidenLockImage: true,
              megameActive: '我投票',
              voteBtnBackColor: 'rgba(153, 107, 209,1)'
            })
          } else {
            this.setData({
              hidenBtn: false,
              hidenLockImage: true,
              megameActive: '我观战',
              voteBtnBackColor: '#66d4d5'
            })
          }
        } else if (newVal.match_status == 24) {
          this.setData({
            megameStatus: '已结束',
            voteBtnW: 100
          })
          if (newVal.user_permission == 0) {
            this.setData({
              hidenBtn: true,
              hidenLockImage: false
            })
          } else if (newVal.user_permission & 2) {
            this.setData({
              hidenBtn: false,
              hidenLockImage: true,
              megameActive: '查看结果',
              voteBtnBackColor: '#ff7e00'
            })
          } else {
            this.setData({
              hidenBtn: false,
              hidenLockImage: true,
              megameActive: '查看结果',
              voteBtnBackColor: '#ff7e00'
            })
          }
        } else if (newVal.match_status == 25) {
          this.setData({
            megameStatus: '未开始',
            voteBtnW: 150,
            hidenBtn: false,
            hidenLockImage: true,
            megameActive: '投票即将开始',
            voteBtnBackColor: 'rgba(153, 107, 209,1)'
          })
        } else {
          this.setData({
            hidenStatus: true,
            hidenBtn: true
          })
          if (newVal.user_permission == 0) {
            this.setData({
              hidenLockImage: false
            })
          } else {
            this.setData({
              hidenLockImage: true
            })
          }
        }
      }
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    megameStatus: '', //大赛状态 21 未开始 22 征稿中 23 评选中 24 已结束
    megameActive: '我投稿', //我投稿 查看投稿 我投票 我观战 查看结果 投票即将开始
    hidenStatus: false, //是否隐藏左下角状态
    hidenLockImage: true, //是否隐藏右上角锁标志
    hidenBtn: true, //是否隐藏右上角按钮
    voteBtnW: 100,
    voteBtnBackColor: '',
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //去投票
    voting(){
      const data = {
        src_action_flag: this.data.dic.src_action_flag,
        megagame_id: this.data.dic.id,
      }
      wx.navigateTo({
        url: '../voting/voting?receiveDic=' + JSON.stringify(data), //传的为对象
      })
    },
    //查看结果
    voteResults() {
      const data = {
        src_action_flag: this.data.dic.src_action_flag,
        megagame_id: this.data.dic.id,
      }
      wx.navigateTo({
        url: '../voteResults/voteResults?receiveDic=' + JSON.stringify(data), //传的为对象
      })
    },
    //创作
    creatKnowledge() {
      const data = {
        pushType: '1',
        src_action_flag: this.data.dic.src_action_flag,
        src_action_title: this.data.dic.title,
        // megagame_id: this.data.dic.id
      }
      wx.navigateTo({
        url: '../production/production?receiveModel=' + JSON.stringify(data),
      })
    },
    //查看所有投稿作品
    viewsubmissions() {
      var idStr = this.data.dic.src_action_flag;
      var titleStr = '';
      console.log('查看投稿作品' + idStr + titleStr);
      wx.navigateTo({
        url: `../projectList/projectList?kgeId=${idStr}&title=${titleStr}&type=1`
      })
    },

    //投稿，投票，查看结果
    toVote(e) {
      var status = this.data.dic.match_status
      var permission = this.data.dic.user_permission
      var needenroll = this.data.dic.need_enroll //是否需要报名
      var hasenroll = this.data.dic.has_enroll //是否已经报名
      if (status == 21) {
        wx: wx.showToast({
          title: '当前比赛尚未开始征稿，开始时间为' + this.data.dic.begin_contribute_time,
          icon: 'none'
        })
      }
      else if (status == 22) {
        if (permission & 1) {
          //展开按钮 当前只做 新创作 已发布的后期加上
          if (needenroll) {
            //需要报名
            if (hasenroll) {
              //新创作
              this.creatKnowledge()
            } else {
              //去报名
              const data = {
                title: '微课大赛报名',
                src_action_flag: this.data.dic.src_action_flag,
                src_action_title: this.data.dic.title,
                megagame_id: this.data.dic.id
              }
              console.log('报名dic' + data)
              wx.navigateTo({
                url: '../xdWebview/xdWebview?receiveDic=' + JSON.stringify(data), //传的为对象
              })
            }
          } else {
            //新创作
            this.creatKnowledge()
          }

        } else {
          //查看投稿作品
          this.viewsubmissions()
        }
      } else if (status == 23) {
        if (permission & 2) {
          //跳转投票页面，可以投票
          this.voting();
        } else {
          //跳转投票结果页面
          this.voteResults();
        }
      } else if (status == 24) {
        //跳转投票结果页面
        this.voteResults();
      } else if (status == 25) {
        if (permission == 0) {
          wx: wx.showToast({
            title: '抱歉，该比赛仅限部分人员参与',
            icon: 'none'
          })
        }
        else {
          //查看作品详情
        }
      }
    }
  }
})